import {createRouter, createWebHistory} from "Vue-router";

const router = createRouter({
    // 路由模式history,
    history: createWebHistory(import.meta.env.VITE_API_BASE_URL),
    // 路由配置
    routes: [
        {path: "/login", name: "login", component: () => import("@/page/login/views/login.vue")},
        {
            path: "/home", name: "home", component: () => import("@/page/home/views/home.vue"),
            children: [
                {path: "/taskWork", name: "taskWork", component: () => import("@/page/taskWork/views/taskWork.vue")},
                {path: "/taskStatus", name: "taskStatus", component: () => import("@/page/taskWork/views/taskStatus.vue")},
                {path: "/supplementData", name: "supplementData", component: () => import("@/page/taskWork/views/supplementData.vue")},
            ]
        }
    ]
});
// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
    if (to.path === '/login') return next()
    // 获取token
    const tokenStr = localStorage.getItem('token')
    if (!tokenStr) return next('/login')
    next()
})


// 将router对象作为组件导出
export default router;